package com.ruoyi.oa.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.oa.domain.OaConfirm;
import com.ruoyi.oa.service.IOaConfirmService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 审核Controller
 * 
 * @author ruoyi
 * @date 2021-10-31
 */
@RestController
@RequestMapping("/confirm")
public class OaConfirmController extends BaseController
{
    @Autowired
    private IOaConfirmService oaConfirmService;

    /**
     * 查询审核列表
     */
    @PreAuthorize(hasPermi = "oa:confirm:list")
    @GetMapping("/list")
    public TableDataInfo list(OaConfirm oaConfirm)
    {
        startPage();
        List<OaConfirm> list = oaConfirmService.selectOaConfirmList(oaConfirm);
        return getDataTable(list);
    }

    /**
     * 导出审核列表
     */
    @PreAuthorize(hasPermi = "oa:confirm:export")
    @Log(title = "审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaConfirm oaConfirm) throws IOException
    {
        List<OaConfirm> list = oaConfirmService.selectOaConfirmList(oaConfirm);
        ExcelUtil<OaConfirm> util = new ExcelUtil<OaConfirm>(OaConfirm.class);
        util.exportExcel(response, list, "审核数据");
    }

    /**
     * 获取审核详细信息
     */
    @PreAuthorize(hasPermi = "oa:confirm:query")
    @GetMapping(value = "/{confirmUuid}")
    public AjaxResult getInfo(@PathVariable("confirmUuid") String confirmUuid)
    {
        return AjaxResult.success(oaConfirmService.selectOaConfirmByConfirmUuid(confirmUuid));
    }

    /**
     * 新增审核
     */
    @PreAuthorize(hasPermi = "oa:confirm:add")
    @Log(title = "审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaConfirm oaConfirm)
    {
        return toAjax(oaConfirmService.insertOaConfirm(oaConfirm));
    }

    /**
     * 修改审核
     */
    @PreAuthorize(hasPermi = "oa:confirm:common")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaConfirm oaConfirm)
    {
        return toAjax(oaConfirmService.updateOaConfirm(oaConfirm));
    }

    /**
     * 删除审核
     */
    @PreAuthorize(hasPermi = "oa:confirm:remove")
    @Log(title = "审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{confirmUuids}")
    public AjaxResult remove(@PathVariable String[] confirmUuids)
    {
        return toAjax(oaConfirmService.deleteOaConfirmByConfirmUuids(confirmUuids));
    }



    /**
     * 审核 - 通用功能
     */
    @PreAuthorize(hasPermi = "oa:confirm:edit")
    @Log(title = "审核（通用）", businessType = BusinessType.UPDATE)
    @PutMapping("/commonConfirm")
    public AjaxResult commonConfirm(@RequestBody OaConfirm oaConfirm)
    {
        return toAjax(oaConfirmService.commonConfirm(oaConfirm));
    }


}
